import OSS from 'ali-oss';

/**
 * oss鉴权并上传文件
 * @param {*} config 
 * @param {*} file 
 * @param {*} url 
 * @returns 
 */
export const ossUpload = (config, file, url) => {
	console.log(config)
	console.log(file)
	console.log(url)
	const client = new OSS(config);
	return new Promise((resolve, reject) => {
		(async () => {
			try {
				const result = await client.put(url + new Date().getTime() + `.${file.name.split('.')[1]}`, file);
				if (result.res.status == 200) {
					resolve({ url: result.url, name: file.name, status: true });
				} else {
					resolve({ url: result.url, name: file.name, status: false });
				}
			} catch (e) {
				reject(e);
			}
		})();
	});
}
